package com.asset.dispoal.business.casedispose.service.command;

import com.asset.dispoal.business.casedispose.domain.db.mapper.CasedisposeMapper;
import com.asset.dispoal.business.casedispose.dto.CaseDisposePageRequest;
import com.asset.dispoal.business.casedispose.dto.CaseDisposePageResponse;
import com.asset.dispoal.commom.page.PagingQuery;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import tech.mhuang.pacebox.core.ddd.BaseCommand;
import tech.mhuang.pacebox.springboot.protocol.Result;
import tech.mhuang.pacebox.springboot.protocol.data.Page;
import tech.mhuang.pacebox.springboot.protocol.data.PageVO;

@Component
public class CaseDisposePageCommand implements BaseCommand<CaseDisposePageRequest, Result<PageVO<CaseDisposePageResponse>>> {

    @Autowired
    CasedisposeMapper casedisposeMapper;

    @Override
    public Result<PageVO<CaseDisposePageResponse>> execute(CaseDisposePageRequest request) {
        Integer count = casedisposeMapper.queryCount(request);
        Page<CaseDisposePageRequest> page = PagingQuery.getPage(count, request);
        PageVO<CaseDisposePageResponse> pageVO = new PageVO<>();
        pageVO.setTotalSize(count);
        if (page != null) {
            pageVO.setResult(casedisposeMapper.queryPage(page));
        }
        return Result.ok(pageVO);
    }
}
